import { userInfoAPI } from "@/request/api.js"
export default {
    namespaced: true,
    state: {
        // 用户信息
        userInfo: {
            nickName: '',
            coin: 0,
            headImg: require('@/assets/img/userImg.f8bbec5e.png'),
        },
        cartTotal: 0
    },

    mutations: {
        // 修改用户信息
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal
        },
        // 初始化
        initUserInfo(state) {
            state.userInfo = {
                nickName: '',
                coin: 0,
                headImg: require('@/assets/img/userImg.f8bbec5e.png'),
            };
            state.cartTotal = 0
        }
    },
    actions: {
        async asyncChangeUserInfo(context) {
            let res = await userInfoAPI()
            // console.log('---res---', res);
            context.commit('changeUserInfo', res.data)
        }
    }
}